package cn.iocoder.yudao.module.ride.service.blacklist;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.ride.controller.admin.blacklist.vo.*;
import cn.iocoder.yudao.module.ride.dal.dataobject.blacklist.BlacklistDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.ride.dal.mysql.blacklist.BlacklistMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.ride.enums.ErrorCodeConstants.*;

/**
 * 黑名单记录 Service 实现类
 *
 * @author tong
 */
@Service
@Validated
public class BlacklistServiceImpl implements BlacklistService {

    @Resource
    private BlacklistMapper blacklistMapper;

    @Override
    public Long createBlacklist(BlacklistSaveReqVO createReqVO) {
        // 插入
        BlacklistDO blacklist = BeanUtils.toBean(createReqVO, BlacklistDO.class);
        blacklistMapper.insert(blacklist);

        // 返回
        return blacklist.getId();
    }

    @Override
    public void updateBlacklist(BlacklistSaveReqVO updateReqVO) {
        // 校验存在
        validateBlacklistExists(updateReqVO.getId());
        // 更新
        BlacklistDO updateObj = BeanUtils.toBean(updateReqVO, BlacklistDO.class);
        blacklistMapper.updateById(updateObj);
    }

    @Override
    public void deleteBlacklist(Long id) {
        // 校验存在
        validateBlacklistExists(id);
        // 删除
        blacklistMapper.deleteById(id);
    }

    @Override
        public void deleteBlacklistListByIds(List<Long> ids) {
        // 删除
        blacklistMapper.deleteByIds(ids);
        }


    private void validateBlacklistExists(Integer id) {
        if (blacklistMapper.selectById(id) == null) {
            throw exception(BLACKLIST_NOT_EXISTS);
        }
    }
    
    private void validateBlacklistExists(Long id) {
        if (blacklistMapper.selectById(id) == null) {
            throw exception(BLACKLIST_NOT_EXISTS);
        }
    }

    @Override
    public BlacklistDO getBlacklist(Long id) {
        return blacklistMapper.selectById(id);
    }

    @Override
    public PageResult<BlacklistDO> getBlacklistPage(BlacklistPageReqVO pageReqVO) {
        return blacklistMapper.selectPage(pageReqVO);
    }

}